package org.stephen.recommend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.stephen.recommend.entity.Tag;
import org.stephen.recommend.mapper.TagMapper;
import org.stephen.recommend.service.BaseService;
import org.stephen.recommend.service.TagService;
import org.stephen.recommend.util.Utils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: TagService
 * Description:
 * Date: 2020/12/8 21:11
 *
 * @author stephen.qiu
 * @version 1.0
 */

@Service
public class TagServiceImpl extends BaseService<TagMapper, Tag> implements TagService {
    @Override
    public List<Tag> getTagListByName(List tagList) {
        if (tagList == null) {
            return null;
        }
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.select("id");
        queryWrapper.in("tag_name", tagList);
        List<Tag> list = this.list(queryWrapper);
        return list;
    }

    @Override
    public String getTagIdByName(String name) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.select("id");
        queryWrapper.eq("tag_name", name);
        Tag tag = this.getOne(queryWrapper);
        return Utils.isEmpty(tag) ? null : tag.getId();
    }
}
